<?php ob_start();  session_start();
include "../conexao.php";

if (!isset($_SESSION["txt_login"]))
{ print "<script type = 'text/javascript'> location.href = 'index.php'</script>"; exit();}


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>

<script language="javascript" type="text/javascript">
//-->
</script></head>
<body>
 <div align="center">
    <h1><strong><font color="red"><u>Empresas</u></font></strong></h1>
  </div><div id="conteudo"><?php
$pagina = $_GET["pagina"];
 if($pagina=="") {
$pagina="1";
}


if($_GET["maximo"]!="" && $_GET["maximo"]<=$qtde_produto){$maximo=$_GET["maximo"];}else{$maximo=30;}

$inicio=$pagina-1;
$inicio=$maximo*$inicio;
?>

<div id="conteudo"> 
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  
  </table>
  <table width="100%" border="0">
  <tr>
    <td width="46%"><br>
      <?php $menos=$pagina-1;
$mais=$pagina+1;
$p_ini=$mais-1;
$p_ini=$maximo*$p_ini;
$p_query = mysql_query("SELECT * FROM empresa ORDER BY id_empresa DESC");
$total = mysql_num_rows($p_query);

$ver = $total%$maximo;
$ver3 = $maximo/2;
if($ver>0){ $qtde_paginas = number_format($total/$maximo); }  else{ $qtde_paginas = $total/$maximo; }
if($ver<$ver3){ $qtde_paginas = number_format($total/$maximo+1); }
if($ver==0){ $qtde_paginas = number_format($total/$maximo); } 

/*$qtde_paginas = number_format($total/$maximo+1);
$ver = $total%$maximo;*/


	     $qtde_links_por_pagina=6;

 echo "<span class=paginacao><a href=\"principal.php?link=3&pagina=1&maximo=$maximo\">primeira p&aacute;gina</a></span>
                             
 ";
$i = $pagina - $qtde_links_por_pagina;

while ($i <= $pagina - 1)
		 {
		     if($i>0)
			 {
			    echo "<span class=paginacao><a href=\"principal.php?link=3&pagina=$i&maximo=$maximo\">$i</a></span>";
			 }                             
			 $i++;
		 }

  echo "<span class=paginacao2>$pagina</span>";
 
         $i = $pagina + 1;
		 while($i<=$pagina + $qtde_links_por_pagina)  
		 {
		     if($i<$qtde_paginas)
			 {
			 echo "<span class=paginacao><a href=\"principal.php?link=3&pagina=$i&maximo=$maximo\">$i</a></span>";
			 }
			 $i++;
		 }
		 //if($qtde_paginas==""){$qtde_paginas=$qtde_paginas-1;}
		 //if($ver==0){  $qtde_paginas=$qtde_paginas-1;  }
	    //if($ver<$maximo && $ver>1){  $qtde_paginas=$qtde_paginas-1;  }
		echo "<span class=paginacao><a href=\"principal.php?link=3&pagina=$qtde_paginas&maximo=$maximo\">&uacute;tima pagina p&aacute;gina</a></span>";?><br></td>
    <td width="54%">&nbsp;</td>
  </tr>
</table>

<table width="1079" align="center">

<tr>
        <td width="17%" class="tarja"><strong>Nome Fantasia</strong></td>
        <!--<td width="6%" align="center" class="tarja"><strong>Cod.Cat/<br />
          Sub.Cat</strong> </td>-->
        <td width="11%" align="center" class="tarja"><strong>Raz&atilde;o social</strong></td>
        <td width="10%" align="center" class="tarja"><strong>Cnpj</strong></td>
        <td width="18%" align="center" class="tarja"><strong>Cpf</strong></td>
        <td width="8%" align="center" class="tarja"><div align="center"><strong>Insc. Rg</strong></div></td>
        <td width="8%" align="center" class="tarja"><div align="center"><strong>Endere&ccedil;o</strong></div></td>
        <td width="8%" align="center" class="tarja"><div align="center"><strong>Bairro</strong></div></td>
        <td width="8%" align="center" class="tarja"><div align="center"><strong>Cidade</strong></div></td>
        <td width="8%" align="center" class="tarja"><div align="center"><strong>Cep</strong></div></td>
        <td width="8%" align="center" class="tarja"><div align="center"><strong>Estado</strong></div></td>
        <td width="8%" align="center" class="tarja"><div align="center"><strong>Telefone 1</strong></div></td>
        <td width="8%" align="center" class="tarja"><div align="center"><strong>Ramal 1</strong></div></td>
        <td width="8%" align="center" class="tarja"><div align="center"><strong>Telefone 2</strong></div></td>
        <td width="8%" align="center" class="tarja"><div align="center"><strong>Ramal 2</strong></div></td>
        <td width="8%" align="center" class="tarja"><div align="center"><strong>Fax</strong></div></td>
        <td width="8%" align="center" class="tarja"><div align="center"><strong>Ramal 3</strong></div></td>
        <td width="8%" align="center" class="tarja"><div align="center"><strong>Pager</strong></div></td>
        <td width="8%" align="center" class="tarja"><div align="center"><strong>Email</strong></div></td>
        <td width="8%" align="center" class="tarja"><div align="center"><strong>Contato</strong></div></td>
        <td width="8%" align="center" class="tarja"><div align="center"><strong>Site</strong></div></td>
        <td width="8%" align="center" class="tarja"><div align="center"><strong>Obs</strong></div></td>
        <td width="8%" align="center" class="tarja"><div align="center"><strong>Cep_Trans</strong></div></td>
       
        
       
        
       
       
      
        <td colspan="3" class="tarja"><div align="center"><strong>          Excluir</strong></div></td>
      </tr>
<?php 



$query=mysql_query("SELECT * FROM empresa  ORDER BY id_empresa DESC LIMIT $inicio, $maximo");
//$total=mysql_num_rows($query);

while($linha=mysql_fetch_array($query)) {?>


<tr>
        <td align="center" class="meio"><?php echo $linha['Nome_Fantasia'];?></td>
        <!--<td class="meio"><div align="center"><?php //echo $linha['id_categoria']."/". $linha['id_subcategoria']; ?></div></td> -->
        <td class="meio"><div align="center"><?php echo $linha['Razao_social']; ?></div></td>
        <td class="meio"><div align="center"><?php echo $linha['CNPJ'];?></div></td>
        <td class="meio"><div align="center">
          <div align="center"><?php echo $linha['CPF'];?></div>
        </div></td>
        <td class="meio"><div align="center"><?php echo $linha['Insc_Rg'];?></div></td>
            <td class="meio"><div align="center"><?php echo $linha['Endereco'];?></div></td>
                <td class="meio"><div align="center"><?php echo $linha['Bairro'];?></div></td>
                    <td class="meio"><div align="center"><?php echo $linha['Cidade'];?></div></td>
                        <td class="meio"><div align="center"><?php echo $linha['Cep'];?></div></td>
                            <td class="meio"><div align="center"><?php echo $linha['Estado'];?></div></td>
                                <td class="meio"><div align="center"><?php echo $linha['Telefone1'];?></div></td>
                                    <td class="meio"><div align="center"><?php echo $linha['Ramal1'];?></div></td>
                                        <td class="meio"><div align="center"><?php echo $linha['Telefone2'];?></div></td>
                                            <td class="meio"><div align="center"><?php echo $linha['Ramal2'];?></div></td>
                                                <td class="meio"><div align="center"><?php echo $linha['Fax'];?></div></td>
                                                    <td class="meio"><div align="center"><?php echo $linha['Ramal3'];?></div></td>
                                                        <td class="meio"><div align="center"><?php echo $linha['Pager'];?></div></td>
                                                            <td class="meio"><div align="center"><?php echo $linha['Email'];?></div></td>
                                                                <td class="meio"><div align="center"><?php echo $linha['Contato'];?></div></td>
                                                                    <td class="meio"><div align="center"><?php echo $linha['site'];?></div></td>
                                                                        <td class="meio"><div align="center"><?php echo $linha['Obs'];?></div></td>
                                                                            <td class="meio"><div align="center"><?php echo $linha['Cep_Trans'];?></div></td>
       
        
        
       
        
       
        
        <td width="11%" align="center" class="meio"><img src="imagens/excluir.gif"  onclick='confirmar_exclusao_lstempresasadmin("acao=Excluir&amp;id_empresa=<?php echo $linha['id_empresa'];?>&pagina=<?php echo $pagina;?>&maximo=<?php echo $maximo;?>")'></td> 
</tr>
	  <?php } ?>
      <tr>
        <td colspan="9">&nbsp;</td>
        <td width="15%" colspan="6"><div align="right"><!--<a href="principal.php?link=7&amp;acao=Inserir&amp;id="><img src="imagens/inserir.gif" width="55" height="16" border="0" /></a> --></div></td>
      </tr></table>


<?php
$menos=$pagina-1;
$mais=$pagina+1;
$p_ini=$mais-1;
$p_ini=$maximo*$p_ini;
$p_query = mysql_query("SELECT * FROM empresa ORDER BY id_empresa DESC");
$total = mysql_num_rows($p_query);

$ver = $total%$maximo;
$ver3 = $maximo/2;
if($ver>0){ $qtde_paginas = number_format($total/$maximo); }  else{ $qtde_paginas = $total/$maximo; }
if($ver<$ver3){ $qtde_paginas = number_format($total/$maximo+1); }
if($ver==0){ $qtde_paginas = number_format($total/$maximo); } 

/*$qtde_paginas = number_format($total/$maximo+1);
$ver = $total%$maximo;*/


	     $qtde_links_por_pagina=6;

 echo "<span class=paginacao><a href=\"principal.php?link=3&pagina=1&maximo=$maximo'\">primeira p&aacute;gina</a></span>
                             
 ";
$i = $pagina - $qtde_links_por_pagina;

while ($i <= $pagina - 1)
		 {
		     if($i>0)
			 {
			    echo "<span class=paginacao><a href=\"principal.php?link=3&pagina=$i&maximo=$maximo\">$i</a></span>";
			 }                             
			 $i++;
		 }

  echo "<span class=paginacao2>$pagina</span>";
 
         $i = $pagina + 1;
		 while($i<=$pagina + $qtde_links_por_pagina)  
		 {
		     if($i<$qtde_paginas)
			 {
			 echo "<span class=paginacao><a href=\"principal.php?link=3&pagina=$i&maximo=$maximo\">$i</a></span>
			                             
						";
			 }
			 $i++;
		 }
		 //if($qtde_paginas==""){$qtde_paginas=$qtde_paginas-1;}
		// if($ver==0){  $qtde_paginas=$qtde_paginas-1;  }
	    //if($ver<$maximo && $ver>1){  $qtde_paginas=$qtde_paginas-1;  }
		echo "<span class=paginacao><a href=\"principal.php?link=3&pagina=$qtde_paginas&maximo=$maximo\">&uacute;tima pagina p&aacute;gina</a></span>";
?>






</div>
</div>
</body>
</html>